/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.arqSw.videominuto.DAO;

import co.edu.uniminuto.arqSw.videominuto.Hibernate.HibernateUtil;
import co.edu.uniminuto.arqSw.videominuto.Hibernate.Serie;
import co.edu.uniminuto.arqSw.videominuto.Hibernate.Video;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

public class VideoListadoDAO {
   Session session = null;
  
   public VideoListadoDAO(){
     this.session = HibernateUtil.getSessionFactory().openSession();
                        }
   
   public List<Video> traePeliculas() {
            
    List<Video> peliculas = new ArrayList<Video>(); 
    
    try{
    Transaction tx = session.beginTransaction();
    tx.begin();
   /*
   Criteria c = session.createCriteria(Video.class);
   c.setFetchMode("Video", FetchMode.EAGER);
   c.setFirstResult(0);
   c.setMaxResults(12);
   peliculas=c.list();*/
    
   Query q=session.createQuery("from Video v where v.tipoVideo=1");
   peliculas =(List<Video>)q.list();
   tx.commit();
   
}catch(Exception e){
e.printStackTrace();
}
//session.close();
return peliculas;
    }

    public List<Video> traeSerie(int isanSerie) {
        
    List<Video> serie = new ArrayList<Video>();     
    
    try{
    Transaction tx = session.beginTransaction();
    tx.begin();  
   
    Query q=session.createQuery("FROM Serie s INNER JOIN s.isanSerie WHERE s.isanSerie=:id");
    q.setParameter("id",isanSerie);
    serie =(List<Video>)q.list();

    tx.commit();
   
}catch(Exception e){
e.printStackTrace();
}
        
        
        return serie;
    }
   
       
      
   
   }
   
   
   

